<style lang="less">
    @import "../../../styles/table.less";
</style>
<template>
    <div>
        <Drawer :closable="false" placement="right" v-model="drawerVisible" width="60%" :title="drawerTitle">
            <Row class="search">
                <Col>
                    <Card>
                        <Form ref="searchUserForm" :model="searchForm" inline :label-width="55" class="search-form">
                            <Form-item label="评论人" prop="userName">
                                <Input type="text" v-model="searchForm.userName" clearable placeholder="请输入员工姓名" style="width: 200px"/>
                            </Form-item>
                            <Form-item label="内容" prop="commentContent">
                                <Input type="text" v-model="searchForm.commentContent" clearable placeholder="请输评论内容" style="width: 200px"/>
                            </Form-item>
                            <Form-item style="margin-left:-35px;" class="br">
                                <Button @click="handleSearchUser" type="primary" icon="ios-search">搜索</Button>
                                <Button @click="handleResetUser">重置</Button>
                            </Form-item>
                        </Form>
                        <Row style="padding-top: 5px">
                            <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" ref="table"></Table>
                        </Row>
                        <Row type="flex" justify="end" class="page">
                            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
                        </Row>
                    </Card>
                </Col>
            </Row>
        </Drawer>
    </div>
</template>

<script>
    import circleLoading from "../../my-components/circle-loading.vue";
    import {list, remove} from "@/api/coursecomment";

    export default {
        name: "courseCommentDrawer",
        components: {
            circleLoading
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                sortColumn: "createTime",
                sortType: "desc",
                dropDownContent: "展开",
                drawerTitle: "评论管理",
                submitLoading: false,
                modalTitle: "添加价格配置",
                drawerVisible: false,
                modalVisible: false,
                dropDownIcon: "ios-arrow-down",
                selectDate: null, //选择日期绑定modal
                total: 0,
                searchForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    courseId: "",
                    targetId: "",
                    commentContent: "",
                    userName: ""
                },
                columns: [
                    /*{
                        type: "selection",
                        width: 60,
                        align: "center"
                    },*/
                    {
                        type: "index",
                        title: "序号",
                        width: 80,
                        align: "center"
                    },
                    {
                        title: "评论内容",
                        key: "commentContent",
                        align: "center",
                        width: 350,
                        sortable: true,
                        render: (h, params) => {
                            let re = "";
                            return h("div", unescape(params.row.commentContent.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1')));
                        }
                    },
                    {
                        title: "评论人",
                        key: "replyUserName",
                        align: "center",
                        width: 140,
                        sortable: true
                    }, {
                        title: "评论时间",
                        key: "createTime",
                        align: "center",
                        width: 160,
                        sortable: true
                    }, {
                        title: "操作",
                        key: "action",
                        width: 200,
                        align: "center",
                        fixed: "right",
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "error",
                                            size: "small"
                                        },
                                        on: {
                                            click: () => {
                                                this.remove(params.row);
                                            }
                                        }
                                    },
                                    "删除"
                                )
                            ]);
                        }
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            init() {

            },
            getList() {
                this.loading = true;
                this.searchForm.targetId = this.searchForm.courseId;
                list(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                });
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getList();
                this.clearSelectAll();
            },
            handleSearchUser() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 9;
                this.getList();
            },
            handleResetUser() {
                this.searchForm.userName = "";
                this.searchForm.commentContent = "";
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 9;
                // 重新加载数据
                this.getList();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getList();
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            showDrawer(params) {
                if (params.courseId) {
                    this.type = 1;
                    this.drawerTitle = "评论管理";
                    this.searchForm.courseId = params.courseId;
                    this.getList();
                }
                this.drawerVisible = true;
            },
            remove(row) {
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除?",
                    onOk: () => {
                        remove(row.id).then(res => {
                            if (res.status === true) {
                                this.$Message.success("删除成功");
                                this.getList();
                            }
                        });
                    }

                });
            }
        },
        mounted() {
            this.init();
        }
    }
</script>
